import { FormProps, FormSchema } from '@/components/Table'
import { BasicColumn } from '@/components/Table/src/types/table'
import { pattern } from '@/utils/validate/index'
import { formatBytes } from '@/utils'
import api from '@/api'
const { systemNameList } = api

// 命名空间列表
export function getTaskBasicColumns(): BasicColumn[] {
  return [
    {
      title: '任务名称',
      width: 220,
      dataIndex: 'taskName'
    },
    {
      title: '镜像名称',
      width: 130,
      customEllipsis: true,
      dataIndex: 'imageName'
    },
    {
      title: '镜像版本',
      customEllipsis: true,
      width: 120,
      dataIndex: 'taskTag'
    },
    {
      title: '镜像地址',
      customEllipsis: true,
      width: 160,
      dataIndex: 'imagePath'
    },
    {
      title: '部署环境',
      width: 80,
      dataIndex: 'deployEnvir'
    },
    {
      title: '副本数',
      align: 'right',
      width: 80,
      dataIndex: 'replicas'
    },
    {
      title: 'CPU 核数',
      align: 'right',
      width: 80,
      dataIndex: 'cpu'
    },
    {
      title: '内存格式',
      width: 80,
      dataIndex: 'ram'
    },
    {
      title: '命名空间',
      width: 160,
      dataIndex: 'nameSpace'
    },
    {
      title: '任务状态 | 失败原因',
      width: 150,
      dataIndex: 'taskStatus'
    },
    {
      title: '创建时间',
      width: 130,
      customEllipsis: true,
      dataIndex: 'createDate'
    },
    {
      title: '操作',
      width: 120,
      dataIndex: 'operate'
    }
  ]
}

let packageDataList: any[] = []
export function getSearchFormConfig(): Partial<FormProps> {
  return {
    labelWidth: 80,
    baseColProps: {
      span: 6,
      md: 8,
      xl: 8,
      xxl: 6
    },
    schemas: [
      {
        field: 'imageName',
        label: '镜像名称',
        component: 'Input'
      },
      {
        field: 'packageName',
        label: '任务名称',
        component: 'ApiTreeSelect',
        componentProps: {
          api: systemNameList,
          immediate: true,
          treeDefaultExpandAll: true,
          afterFetch: (options: any) => {
            let newArr: any[] = []
            if (options && options.length) {
              options.forEach((item: any) => {
                let obj: any = {
                  label: item.systemName,
                  value: item.systemName,
                  extraValue: item.systemName,
                  disabled: true
                }
                if (item.systemList && item.systemList.length) {
                  obj.children = []
                  item.systemList.forEach((itemChild: any) => {
                    obj.children.push({
                      label: itemChild.appName,
                      value: itemChild.packageName,
                      extraValue: itemChild.packageName + '~~' + itemChild.appName
                    })
                  })
                }
                newArr.push(obj)
              })
            }
            packageDataList = newArr
            return newArr
          }
        }
      },
      {
        field: 'deployEnvir',
        label: '部署环境',
        component: 'Select',
        componentProps: {
          options: [
            {
              label: '灰度',
              value: 0,
              key: 0
            },
            {
              label: '生产',
              value: 1,
              key: 1
            }
          ]
        }
      }
    ]
  }
}
export function getPackageDataList() {
  return packageDataList
}
